//
//  HotTableviewCell.m
//  212--Homework  QQy音乐  阿里星球
//
//  Created by 冀永金 on 16/8/13.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "HotTableviewCell.h"
#import "PhoneSongCollectionViewCell.h"
#import "FirstModel.h"
#import "SecondModel.h"
#import "ThirdModel.h"
#import "JYYNetWorkParser.h"
#import "HotCollectionCell.h"
@interface HotTableviewCell ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
@property (nonatomic, strong) UICollectionView *collection;
@property (nonatomic, strong) FirstModel *first;

@end
@implementation HotTableviewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _titleLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_titleLabel];
        _titleLabel.textAlignment = 1;
        _titleLabel.font = [UIFont systemFontOfSize:20];
        _titleLabel.textColor = [UIColor whiteColor];
        [self config];
        [self handleData];
        
    }
    return self;
}
- (void)config {
    _layout = [[UICollectionViewFlowLayout alloc]init];
    _layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    //_layout.minimumLineSpacing = 5;
    _layout.minimumInteritemSpacing = 5;
    _collection = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:_layout];
    [self.contentView addSubview:_collection];
    _collection.delegate = self;
    _collection.dataSource = self;
    _collection.showsVerticalScrollIndicator = NO;
    _collection.scrollEnabled = NO;
   
    [_collection registerClass:[HotCollectionCell class] forCellWithReuseIdentifier:@"pool"];
}
- (void)handleData {
    [JYYNetWorkParser GETWithURL:@"http://api.dongting.com/frontpage/frontpage?location=0&version=1470998222737&app=ttpod&v=v9.0.4.2016070616&user_id=0&mid=iPhone8%2C1&f=f320&s=s310&imsi=&hid=&splus=10.0&active=1&net=2&openudid=4bbd8925c4a3991ee51c9cd8b9a8dc5961820764&idfa=2BBAE4F7-2E3B-41AA-AE0C-F91FB2BDC279&utdid=V62kivWPJBYDABK%2FL8gCUnDI&alf=(null)&bundle_id=com.ttpod.music&latitude=(null)&longtitude=(null)&access_token=(null)&vc=9000400" par:nil success:^(id responseObject) {
        self.first = [FirstModel modelWithDic:responseObject];
        [self.collection reloadData];
    } filed:^(NSError *error) {
        
    }];
    
    
}


- (void)layoutSubviews {
    [super layoutSubviews];
    self.titleLabel.frame = CGRectMake(self.bounds.size.width / 2 - 70, 20, 140, 40);
    _layout.itemSize = CGSizeMake((self.bounds.size.width - 30) / 3, 200);
    _collection.frame = CGRectMake(0, 60, self.bounds.size.width, 410);
    
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.first.data[5].data.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    HotCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"pool" forIndexPath:indexPath];
    ThirdModel *third = self.first.data[5].data[indexPath.row];
    [cell setThird:third];
    return cell;
    
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
